//
//  XJCommunityItem.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/5/30.
//  Copyright © 2018年 Tzyang. All rights reserved.
//

#import "XJCommunityItem.h"
@interface XJCommunityItem()
@property(nonatomic, strong)UIView *bgView;
@property(nonatomic, strong) UIImageView *iconIv;
@property(nonatomic, strong) UILabel *tagLabel;

@end
@implementation XJCommunityItem

#pragma mark - 一初始化
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupView];
    }
    return self;
}

- (void)setupView{
    [self.contentView addSubview:self.bgView];
    
    [self.bgView addSubview:self.iconIv];
    [self.bgView addSubview:self.tagLabel];
}

#pragma mark - 二lazy
- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc] init];
    }
    return _bgView;
}

- (UIImageView *)iconIv {
    if (!_iconIv) {
        _iconIv = [[UIImageView alloc] init];
    }
    return _iconIv;
}
- (UILabel *)tagLabel {
    if (!_tagLabel) {
        _tagLabel = [[UILabel alloc] init];
    }
    return _tagLabel;
}

#pragma mark - 三layout
- (void)layoutSubviews {
    [super layoutSubviews];
    
  
    
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];
    
    [self.iconIv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bgView);
        if (UI_IS_IPHONE5) {
            make.size.mas_equalTo(CGSizeMake(38, 38));
        }else{
            make.size.mas_equalTo(CGSizeMake(48, 48));
        }
        make.centerX.mas_equalTo(self);
    }];
    
    
    [self.tagLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.bgView);
        [make.top.mas_equalTo(self.iconIv.mas_bottom)setOffset:10];
    }];
}

#pragma mark - 三-2 配置item
- (void)configureIconImgStr:(NSString *)iconStr tagStr:(NSString *)tagStr {
    UIImage *placeImg = [UIImage imageNamed:@"default_goods"];
    
    
    [self.iconIv sd_setImageWithURL:[NSURL URLWithString:iconStr] placeholderImage:placeImg];
    self.tagLabel.text = tagStr;
}

#pragma mark - 四事件

@end
